package cn.wjssl.test.infrastructure;

import cn.wjssl.domain.strategy.model.entity.StrategyAwardEntity;
import cn.wjssl.domain.strategy.repository.IStrategyRepository;
import cn.wjssl.infrastructure.persistent.dao.*;
import cn.wjssl.infrastructure.persistent.po.RaffleActivityOrderPO;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils;
import org.jeasy.random.EasyRandom;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Author：lxd
 * @Description
 * @Date：2025/1/25
 */

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class DaoTest {

    @Resource
    private IAwardDao awardDao;

    @Resource
    private IStrategyAwardDao strategyAwardDao;

    @Resource
    private IStrategyRepository repository;

    @Resource
    private IRaffleActivityDao activityDao;

    @Resource
    private IRaffleActivitySkuDao activitySkuDao;

    @Resource
    private IRaffleActivityOrderDao activityOrderDao;

    private final EasyRandom easyRandom = new EasyRandom();

    @Test
    public void test() {
        // List<Award> awards = awardDao.queryAwardList();
        // log.info(JSON.toJSONString(awards));
        // List<StrategyAward> strategyAwards = strategyAwardDao.queryStrategyAwardList();
        // log.info(JSON.toJSONString(strategyAwards));
        List<StrategyAwardEntity> strategyAwardEntities = repository.queryStrategyAwardList(100001L);
        System.out.println(JSON.toJSONString(strategyAwardEntities));
    }

    @Test
    public void testActivity() {

//        RaffleActivityPO raffleActivityPO = activityDao.queryRaffleActivityByActivityId(100301l);
//        System.out.println(JSON.toJSONString(raffleActivityPO));

//        RaffleActivitySkuPO raffleActivitySkuPO = activitySkuDao.queryActivitySku(9011L);
//        System.out.println(JSON.toJSONString(raffleActivitySkuPO));

        for (int i = 0; i < 5; i++) {
            RaffleActivityOrderPO raffleActivityOrder = new RaffleActivityOrderPO();
            // EasyRandom 可以通过指定对象类的方式，随机生成对象值。如；easyRandom.nextObject(String.class)、easyRandom.nextObject(RaffleActivityOrder.class)
            raffleActivityOrder.setUserId(easyRandom.nextObject(String.class));
            raffleActivityOrder.setSku(9011L);
            raffleActivityOrder.setActivityId(100301L);
            raffleActivityOrder.setActivityName("测试活动");
            raffleActivityOrder.setStrategyId(100006L);
            raffleActivityOrder.setOrderId(RandomStringUtils.randomNumeric(12));
            raffleActivityOrder.setTotalCount(0);
            raffleActivityOrder.setDayCount(0);
            raffleActivityOrder.setMonthCount(0);
            raffleActivityOrder.setOutBusinessNo(RandomStringUtils.randomNumeric(9));
            raffleActivityOrder.setOrderTime(new Date());
            raffleActivityOrder.setState("not_used");
            // 插入数据
            activityOrderDao.insert(raffleActivityOrder);
        }

//        List<RaffleActivityOrderPO> jxkyvRnL = activityOrderDao.queryRaffleActivityOrderByUserId("JxkyvRnL");
//        System.out.println(JSON.toJSONString(jxkyvRnL));
    }

}
